package com.konsung.util;

import android.app.ActivityManager;
import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.graphics.Bitmap;
import android.graphics.drawable.Drawable;
import android.net.ConnectivityManager;
import android.net.Network;
import android.net.NetworkInfo;
import android.net.NetworkRequest;
import android.os.Build;
import android.os.Environment;
import android.os.Handler;
import android.os.Looper;
import android.os.StatFs;
import android.support.v4.content.ContextCompat;
import android.view.View;
import android.view.WindowManager;
import android.view.inputmethod.InputMethodManager;
import android.widget.ImageView;
import android.widget.TextView;

import com.konsung.bean.ConfigDto;
import com.konsung.bean.MeasureDataBean;
import com.konsung.bean.PatientBean;
import com.konsung.greendaoUtil.ConfigDtoDao;
import com.konsung.greendaoUtil.GreenDaoManager;
import com.konsung.healthfile.R;
import com.konsung.ui.MyApplication;
import com.konsung.ui.defineview.WaitingDialog;
import com.konsung.util.constant.GlobalConstant;
import com.synjones.bluetooth.BmpUtil;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.text.SimpleDateFormat;
import java.util.List;
import java.util.Locale;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * Created by Administrator on 2015/12/28 0028.
 * 常用工具类
 */
public class UiUtils {
    private static Context mContext;
    private static long lastClickTime;
    private static PatientBean current;
    private static List<MeasureDataBean> measureDataBeen; //为体检报告提供快速获取通道
    private static Handler mHandler = new Handler(Looper.getMainLooper());
    //等待的对话框
    private static WaitingDialog waitingDialog;


    /**
     * 显示加载的进度条
     *
     * @param context 上下文
     * @param content 显示的内容
     */
    public static void showProgress(final Context context, final String content) {
        UiUtils.post(new Runnable() {
            @Override
            public void run() {
                if (null == waitingDialog) {
                    waitingDialog = new WaitingDialog(context, content);
                    waitingDialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
                }

                if (waitingDialog.isShowing()) {
                    return;
                }

                waitingDialog.setCancelable(false);
                waitingDialog.show();
                waitingDialog.setText(content);
            }
        });
    }

    /**
     * 隐藏进度条
     */
    public static void hideProgress() {
        UiUtils.post(new Runnable() {
            @Override
            public void run() {
                if (null != waitingDialog && waitingDialog.isShowing()) {
                    waitingDialog.dismiss();
                    waitingDialog = null;
                }
            }
        });
    }
    /**
     * 获取PatientBean
     * @return 当前居民
     */
    public static PatientBean getCurrent() {
        return current;
    }

    /**
     * 设置当前居民
     * @param current 当前居民
     */
    public static void setCurrent(PatientBean current) {
        UiUtils.current = current;
    }

    /**
     * 获取当前居民测量数据
     * @return 当前居民
     */
    public static List<MeasureDataBean> getMeasureDataBeen() {
        return measureDataBeen;
    }

    /**
     * 设置当前居民测量数据
     * @param measureDataBeen 测量数据
     */
    public static void setMeasureDataBeen(List<MeasureDataBean> measureDataBeen) {
        UiUtils.measureDataBeen = measureDataBeen;
    }

    /**
     * 初始化数据
     * @param context 上下文
     */
    public static void initData(Context context) {
        mContext = context;
        mHandler = new Handler();
    }

    /**
     * 获取加密后的字符串
     * @param pw 要转换md5的字符串
     * @return 返回已经转换的md5字符串
     */
    public static String stringMD5(String pw) {
        try {

            // 拿到一个MD5转换器（如果想要SHA1参数换成”SHA1”）
            MessageDigest messageDigest = MessageDigest.getInstance("MD5");
            // 输入的字符串转换成字节数组
            byte[] inputByteArray = pw.getBytes();
            // inputByteArray是输入字符串转换得到的字节数组
            messageDigest.update(inputByteArray);
            // 转换并返回结果，也是字节数组，包含16个元素
            byte[] resultByteArray = messageDigest.digest();
            // 字符数组转换成字符串返回
            return byteArrayToHex(resultByteArray);
        } catch (NoSuchAlgorithmException e) {
            return null;
        }
    }

    /**
     * @param byteArray 要转换的字符串
     * @return 返回的字符
     */
    public static String byteArrayToHex(byte[] byteArray) {

        // 首先初始化一个字符数组，用来存放每个16进制字符
        char[] hexDigits = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
                'A', 'B', 'C', 'D', 'E', 'F'};
        // new一个字符数组，这个就是用来组成结果字符串的（解释一下：一个byte是八位二进制，也就是2位十六进制字符（2的8次方等于16的2
        // 次方））
        char[] resultCharArray = new char[byteArray.length * 2];
        // 遍历字节数组，通过位运算（位运算效率高），转换成字符放到字符数组中去
        int index = 0;
        for (byte b : byteArray) {
            resultCharArray[index++] = hexDigits[b >>> 4 & 0xf];
            resultCharArray[index++] = hexDigits[b & 0xf];
        }
        // 字符数组组合成字符串返回
        return new String(resultCharArray);
    }

    /**
     * 获取包名
     * @return 包名
     */
    public static String getPackName() {
        return mContext.getPackageName();
    }

    /**
     * 获取上下文
     * @return 上下文
     */
    public Context getmContext() {
        return mContext;
    }

    /**
     * 获取本应用应用程序的软件版本号
     * @return 软件版本号
     */
    public static int getAppVersion() {
        try {
            PackageManager manager = mContext.getPackageManager();
            PackageInfo info = manager.getPackageInfo(mContext.getPackageName(), 0);
            int version = info.versionCode;
            return version;
        } catch (Exception e) {
            e.printStackTrace();
            e.printStackTrace();
            return 0;
        }
    }

    /**
     * 抛出runnable
     * @param task 任务
     * @param time 延时时长
     */
    public static void postDelayed(Runnable task, long time) {
        mHandler.postDelayed(task, time);
    }

    /**
     * 抛出runnable
     * @param task 任务
     */
    public static void removeDelayed(Runnable task) {
        mHandler.removeCallbacks(task);
    }

    /**
     * 获取进程的上下文
     * @return 程的上下文
     */
    public static Context getContent() {
        return mContext;
    }

    /**
     * 获取字符
     * @param resId 字符id
     * @return 字符
     */
    public static String getString(int resId) {
        return mContext.getString(resId);
    }

    /**
     * 获取dimen 大小
     * @param dimenId dimen id
     * @return 间距
     */
    public static int getDimen(int dimenId) {
        return mContext.getResources().getDimensionPixelSize(dimenId);
    }

    /**
     * 获取字符数组
     * @param resId 字符id
     * @return 字符数组
     */
    public static String[] getStringArr(int resId) {
        return mContext.getResources().getStringArray(resId);
    }

    /**
     * 通过未销毁的上下文获取 Drawable
     * @param resId Drawable
     * @return Drawable
     */
    public static Drawable getDrawable(int resId) {
        return ContextCompat.getDrawable(mContext, resId);
    }

    /**
     * 根据传入的枚举数据返回不同的时间值
     * @param state 枚举日期类型
     * @return SimpleDateFormat
     */
    public static SimpleDateFormat getDateFormat(DateState state) {
        SimpleDateFormat dateFormat = null;
        switch (state) {
            case LONG:
                dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                break;
            case SHORT:
                dateFormat = new SimpleDateFormat("yyyy-MM-dd");
                break;
            case CHINESE:
                dateFormat = new SimpleDateFormat("yyyy年MM月dd日");
                break;
            default:
                dateFormat = new SimpleDateFormat("yyyy-MM-dd");
                break;
        }
        return dateFormat;
    }

    /**
     * 处理长字符显示
     * @param tv 文本空间
     * @param connect 显示的内容
     */
    public static void setLongText(TextView tv, String connect) {
        if (tv != null && connect != null) {
            if (connect.length() > 10) {
                tv.setText(connect.substring(0, 10) + "…");
            } else {
                tv.setText(connect);
            }
        }
    }

    /**
     * 获取颜色
     * @param id id
     * @return 颜色值
     */
    public static int getColor(int id) {
        return mContext.getResources().getColor(id);
    }

    /**
     * 根据居民信息设置头像
     * @param ivHeadPhoto 头像控件
     * @param patientBean 居民信息
     */
    public static void setHeadPhoto(ImageView ivHeadPhoto, PatientBean patientBean) {
        if (patientBean != null) {
            Bitmap bitmap = BmpUtil.getBitmapByFileName(patientBean.getIdcard());
            if (bitmap != null) {
                //若存在身份证头像则显示身份证头像
                ivHeadPhoto.setImageBitmap(bitmap);
            } else {
                switch (patientBean.getSex()) {
                    case 1:
                        ivHeadPhoto.setImageDrawable(getDrawable(R.mipmap.pic_male));
                        return;
                    case 2:
                        ivHeadPhoto.setImageDrawable(getDrawable(R.mipmap.pic_female));
                        return;
                    default:
                        break;
                }
                ivHeadPhoto.setImageDrawable(getDrawable(R.mipmap.pic_unknow));
            }
        } else {
            ivHeadPhoto.setImageDrawable(getDrawable(R.mipmap.pic_unknow));
        }
    }

    /**
     * 匹配字符串是否纯数字
     * @param str 字符
     * @return 是否纯数字
     */
    public static boolean isNumber(String str) {
        String reg = "^\\d+$";
        return str.matches(reg);
    }

    /**
     * 匹配字符串是否包含特殊字符
     * @param str 字符
     * @return 是否包含特殊字符 [^<>&/|'\]+
     */
    public static boolean legalName(String str) {
        String regEx = "[/^&*+\\|[{(（）)}]\'<>]+";
        Pattern p = Pattern.compile(regEx);
        Matcher m = p.matcher(str);
        return m.find() || str.contains("\\") || str.contains("]");
    }

    /**
     * 用于区分时间格式的枚举
     * LONG 表示长时间
     * SHORT 表示短时间
     */
    public enum DateState {
        LONG,
        SHORT,
        CHINESE
    }

    /**
     * 获得可用的内存
     * @return 可用的内存
     */
    public static long getmemCurrent() {
        long memUnused;
        // 得到ActivityManager
        ActivityManager am = (ActivityManager) mContext.getSystemService(
                Context.ACTIVITY_SERVICE);
        // 创建ActivityManager.MemoryInfo对象
        ActivityManager.MemoryInfo mi = new ActivityManager.MemoryInfo();
        am.getMemoryInfo(mi);
        // 取得剩余的内存空间
        memUnused = mi.availMem / 1024;
        return memUnused;
    }

    /**
     * 根据体重和身高计算BMI
     * @param height 身高
     * @param weight 体重
     * @return BMI值
     */
    public static String countBmi(String height, String weight) {
        String result = "";
        if (android.text.TextUtils.isEmpty(height)
                || android.text.TextUtils.isEmpty(weight)
                || Float.valueOf(height) == GlobalConstant.INVALID_DATA
                || Float.valueOf(weight) == GlobalConstant.INVALID_DATA) {
            return result;
        }
        double a = Double.parseDouble(height) / GlobalConstant.FACTOR * 0.01;
        if (a == 0) {
            return "0";
        }
        double b = Double.parseDouble(weight) / GlobalConstant.FACTOR;
        double bmi = b / (a * a);
        if (bmi >= 0 && bmi <= 50) {
            return String.format(Locale.ENGLISH, "%.2f", bmi);
        } else {
            return "";
        }
    }

    /**
     * 获得总内存
     * @return 总内存
     */
    public static long getmemTotal() {
        long mTotal;
        // /proc/meminfo读出的内核信息进行解释
        String path = "/proc/meminfo";
        String content = null;
        BufferedReader br = null;
        try {
            br = new BufferedReader(new FileReader(path), 8);
            String line;
            if ((line = br.readLine()) != null) {
                content = line;
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (br != null) {
                try {
                    br.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
        // beginIndex
        int begin = content.indexOf(':');
        // endIndex
        int end = content.indexOf('k');
        // 截取字符串信息

        content = content.substring(begin + 1, end).trim();
        mTotal = Integer.parseInt(content);
        return mTotal;
    }

    /**
     * post到主线线程执行
     * @param task 线程
     */
    public static void post(Runnable task) {
        mHandler.post(task);
    }

    /**
     * post到子线线程执行
     * @param runnable 线程
     */
    public static void postShortThread(Runnable runnable) {
        ThreadManager.getInstance().createShortPool().execute(runnable);
    }

    /**
     * post到子线线程执行
     * @param runnable 线程
     */
    public static void postLongThread(Runnable runnable) {
        ThreadManager.getInstance().createLongPool().execute(runnable);
    }

    /**
     * 取消子线程
     * @param runnable 线程
     */
    public static void cancelThread(Runnable runnable) {
        ThreadManager.getInstance().createLongPool().cancel(runnable);
    }

    /**
     * // 获取系统总CPU使用时间
     * @return 总CPU使用时间
     */
    public static long getTotalCpuTime() {
        String[] cpuInfos = null;
        try {
            BufferedReader reader = new BufferedReader(new InputStreamReader(
                    new FileInputStream("/proc/stat")), 1000);
            String load = reader.readLine();
            reader.close();
            cpuInfos = load.split(" ");
        } catch (IOException ex) {
            ex.printStackTrace();
        }
        long totalCpu = Long.parseLong(cpuInfos[2])
                + Long.parseLong(cpuInfos[3]) + Long.parseLong(cpuInfos[4])
                + Long.parseLong(cpuInfos[6]) + Long.parseLong(cpuInfos[5])
                + Long.parseLong(cpuInfos[7]) + Long.parseLong(cpuInfos[8]);
        return totalCpu;
    }

    /**
     * 获取应用占用的CPU时间
     * @return 应用占用的CPU时间
     */
    public static long getAppCpuTime() {
        String[] cpuInfos = null;
        try {
            int pid = android.os.Process.myPid();
            BufferedReader reader = new BufferedReader(new InputStreamReader(
                    new FileInputStream("/proc/" + pid + "/stat")), 1000);
            String load = reader.readLine();
            reader.close();
            cpuInfos = load.split(" ");
        } catch (IOException ex) {
            ex.printStackTrace();
        }
        long appCpuTime = Long.parseLong(cpuInfos[13])
                + Long.parseLong(cpuInfos[14]) + Long.parseLong(cpuInfos[15])
                + Long.parseLong(cpuInfos[16]);
        return appCpuTime;
    }

    /**
     * 校验IP或者域名
     * @param ipAddress ip
     * @return 是否合法
     */
    public static boolean isValidIP(String ipAddress) {
        String ip = "^(http|https|ftp)\\://([a-zA-Z0-9\\.\\-]+(\\:[a-zA-Z0-9\\.&amp;%\\$\\-]+)*@)" +
                "*((25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9])\\." +
                "(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\\." +
                "(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\\." +
                "(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[0-9])|localhost|" +
                "([a-zA-Z0-9\\-]+\\.)*[a-zA-Z0-9\\-]+\\." +
                "(com|edu|gov|int|mil|net|org|biz|arpa|info|name|pro|aero|coop|museum|" +
                "[a-zA-Z]{1}))(\\:[0-9]+)*([a-zA-Z])*$";
        Pattern pattern = Pattern.compile(ip);
        Matcher matcher = pattern.matcher(ipAddress);
        return matcher.matches();
    }

    /**
     * 获取当前应用的版本名字
     * @return 应用的版本名字
     */
    public static String getappVersionName() {
        PackageInfo packageInfo = null;
        try {
            packageInfo = mContext.getPackageManager()
                    .getPackageInfo(getPackName(), 0);
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
        }
        if (packageInfo == null) {
            return "未知版本";
        }
        String name = packageInfo.versionName;
        return name;
    }

    /**
     * 获取软件名称的方法
     * @return 软件名称
     */
    public static String getAreaName() {
        String s = getappVersionName();
        return s.substring(s.indexOf("-") + 1).replace("-dev", "");
    }

    /**
     * 创建文件
     * @param path 文件路径
     */
    public static void createFile(String path) {
        File file = new File(path);
        if (!file.exists()) {
            file.mkdirs();
        }
    }

    /**
     * 设置当前居民
     * @param idCard 当前居民身份证号码
     */
    public static void setCurrentPatient(String idCard) {
        SpUtils.saveToSp(GlobalConstant.APP_CONFIG, GlobalConstant.CURRENT_PATIENT, idCard);
        ReferenceUtils.initPersonalReference(); //切换当前居民，更新参考值范围
        BroadcastUtils.sendReplacePatientForAll();
    }

    /**
     * 隐藏键盘
     * @param v 需要隐藏键盘的view
     */
    public static void hideKeyboard(View v) {
        InputMethodManager imm = (InputMethodManager) v.getContext().getSystemService(Context
                .INPUT_METHOD_SERVICE);
        if (imm.isActive()) {
            imm.hideSoftInputFromWindow(v.getApplicationWindowToken(), 0);
        }
    }

    /**
     * 根据参数值获取单位字符串
     * @param param 参数
     * @return 单位
     */
    public static String getValueUnit(int param) {
        switch (param) {
            case KParamType.ECG_HR:
            case KParamType.SPO2_PR:
                return UiUtils.getString(R.string.health_unit_bpm);

            case KParamType.NIBP_SYS:
            case KParamType.NIBP_DIA:
                return UiUtils.getString(R.string.unit_mmhg);

            case KParamType.TEMP_T1:
            case KParamType.IRTEMP_TREND:
                return UiUtils.getString(R.string.unit_temp);

            case KParamType.BLOOD_HCT:
            case KParamType.SPO2_TREND:
            case KParamType.GHB_HBA1C_NGSP:
                return UiUtils.getString(R.string.unit_percent);

            case KParamType.BLOODGLU_AFTER_MEAL:
            case KParamType.BLOODGLU_BEFORE_MEAL:
            case KParamType.URICACID_TREND:
            case KParamType.CHOLESTEROL_TREND:
            case KParamType.BLOOD_FAT_CHO:
            case KParamType.BLOOD_FAT_HDL:
            case KParamType.BLOOD_FAT_LDL:
            case KParamType.BLOOD_FAT_TRIG:
            case KParamType.URINERT_KET:
            case KParamType.URINERT_GLU:
            case KParamType.URINERT_VC:
                return UiUtils.getString(R.string.unit_mmol_l);

            case KParamType.GHB_HBA1C_IFCC:
                return UiUtils.getString(R.string.unit_mmol_mol);
            case KParamType.URINERT_LEU:
            case KParamType.URINERT_BLD:
                return UiUtils.getString(R.string.unit_cells);

            case KParamType.URINERT_UBG:
            case KParamType.URINERT_BIL:
                return UiUtils.getString(R.string.unit_umol);
            case KParamType.URINERT_PRO:
            case KParamType.BLOOD_HGB:
                return UiUtils.getString(R.string.unit_gl);
            case KParamType.BLOOD_WBC:
                return UiUtils.getString(R.string.unit_index);
            case KParamType.GHB_EAG:
                return UiUtils.getString(R.string.unit_mg_dl);
            case KParamType.WEIGHT:
                return getString(R.string.unit_kg);
            case KParamType.HEIGHT:
                return getString(R.string.unit_cm);
            default:
                return "";
        }
    }

    /**
     * 获取参数比例
     * @param param 参数
     * @return 比例
     */
    public static float getFactor(int param) {
        switch (param) {
            case KParamType.URINERT_SG:
                return GlobalConstant.SG_FACTOR;
            case KParamType.BLOOD_WBC:
                return GlobalConstant.WBC_FACTOR;
            default:
                return GlobalConstant.FACTOR;
        }
    }

    /**
     * 设置测量结果,尿常规不能用
     * @param param 参数
     * @param value 结果
     * @param tvValue 结果TextView
     * @param hasPoint 值是否有小数点
     */
    public static void setMeasureResult(int param, int value, TextView tvValue,
            boolean hasPoint) {
        if (value == GlobalConstant.INVALID_DATA) {
            tvValue.setText(getString(R.string.invalid_data) + getValueUnit(param));
            return;
        }
        if (value == OverCheckUtil.FLAG_OVER_MAX) {
            tvValue.setText(OverCheckUtil.getOverMaxString(param, value));
        } else if (value == OverCheckUtil.FLAG_BELOW_MIN) {
            tvValue.setText(OverCheckUtil.getOverMinString(param, value));
        } else {
            if (hasPoint) {
                tvValue.setText(String.valueOf(value / getFactor(param))
                        + getValueUnit(param));
            } else {
                tvValue.setText(String.valueOf((int) (value / getFactor(param)))
                        + getValueUnit(param));
            }
        }
    }

    /**
     * 对浮点数保留两位小数
     * @param num 浮点数
     * @return 保留两位小数
     */
    public static String twoDecimals(double num) {
        return String.format(Locale.ENGLISH, "%.2f", num);
    }

    /**
     * 判断是否连接到网络
     * @param context context
     * @return 是否连接到网络
     */
    public static synchronized boolean isNetWorkConnected(Context context) {
        ConnectivityManager connm = (ConnectivityManager) context
                .getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo ni = connm.getActiveNetworkInfo();
        return ni != null && ni.isConnectedOrConnecting();
    }

    /**
     * 判断当前内存容量是否内存是否足够
     * @param min 目标值 单位字节
     * @return 内存是否足够
     */
    public static boolean isMemoryEnough(long min) {
        File path = Environment.getExternalStorageDirectory();
        StatFs stat = new StatFs(path.getPath());
        long blockSize = stat.getBlockSizeLong();
        long availableBlocks = stat.getAvailableBlocksLong();
        if (blockSize * availableBlocks > min) {
            return true;
        } else {
            return false;
        }
    }

    /**
     * 判断当前是否有网络
     * @param context 上下问
     * @return 是否有网络
     */
    public static boolean isConnectNetWork(Context context) {
        //获取系统的网络服务
        ConnectivityManager connManager = (ConnectivityManager) context
                .getSystemService(Context.CONNECTIVITY_SERVICE);
        if (null == connManager) {
            return false;
        }
        Network[] networks = null;
        //版本号大于21
        if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES
                .LOLLIPOP) {
            NetworkRequest.Builder builder = null;
            builder = new NetworkRequest.Builder();
            connManager.requestNetwork(builder.build(), new ConnectivityManager
                    .NetworkCallback());
            networks = connManager.getAllNetworks();
            for (Network network : networks) {
                NetworkInfo networkInfo = connManager.getNetworkInfo(network);
                if (networkInfo == null || !networkInfo.isAvailable()) {
                } else {
                    //有网络
                    if (networkInfo.getState() != null && networkInfo.isConnected()) {
                        return true;
                    }
                }
            }
            //版本号小于21，大于等于19
        } else if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES
                .LOLLIPOP && android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES
                .KITKAT) {
            NetworkInfo[] infos = connManager.getAllNetworkInfo();
            for (NetworkInfo info : infos) {
                if (info != null && info.isAvailable() && info.getState() != null &&
                        info.isConnected()) {
                    //有网络
                    return true;
                }
            }
        }
        return false;
    }

    /** 是否是沭阳地区使用
     * @return boolean
     */
    public static Boolean isShuYangArea() {
        ConfigDtoDao configDao = GreenDaoManager
                .getConfigDao(MyApplication.getContext());
        List<ConfigDto> list = configDao.queryBuilder()
                .where(ConfigDtoDao.Properties.Type.eq(GlobalConstant.AREA_SHUYANG))
                .list();
        if (list.size() > 0) {
            for (ConfigDto dto : list) {
                if (GlobalConstant.AVAILABLE_Y.equals(dto.getIsAvailable())) {
                    return true;
                }
            }
        }
        return false;
    }

    /**
     * 将身份证图片转化为BitMap
     *
     * @param picArr      图片字节数组
     * @param fileName 文件名
     */
    public static void savePhoto(byte[] picArr, String fileName) {
        if (picArr != null) {
            BmpUtil.saveHeadPic(picArr, fileName);
        }
    }
}
